package com.sora.novel.book.manager.feign;

import com.sora.novel.common.constant.ErrorCodeEnum;
import com.sora.novel.common.resp.RestResp;
import com.sora.novel.user.dto.resp.UserInfoRespDto;
import com.sora.novel.user.feign.UserFeign;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * @Classname: UserFeignManager
 * @Description: 用户微服务调用 Feign 客户端管理
 * @Author: Stonffe
 * @Date: 2023/6/15 20:37
 */
@Component
@RequiredArgsConstructor
public class UserFeignManager {
    private final UserFeign userFeign;

    public List<UserInfoRespDto> listUserInfoByIds(List<Long> userIds) {

        RestResp<List<UserInfoRespDto>> resp = userFeign.listUserInfoByIds(userIds);
        if (Objects.equals(ErrorCodeEnum.OK.getCode(), resp.getCode())) {
            return resp.getData();
        }
        return new ArrayList<>(0);
    }
}
